﻿using DevExpress.Mvvm;
using DevExpress.Xpf.Grid;
using PlaceOrder_Client.Models.Common;
using PlaceOrder_Client.ViewModels;
using Prism.DryIoc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace PlaceOrder_Client.Views
{
    /// <summary>
    /// OnHoldPositionsView.xaml 的交互逻辑
    /// </summary>
    public partial class OnHoldPositionsView : System.Windows.Window
    {
        public OnHoldPositionsView()
        {
            InitializeComponent();
            Messenger.Default.Register<string>(this, MessageToken.ExpandWeiPing, ExpandWeiPingHandler);
        }

        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            MainViewModel._onHoldView = null;
        }

        private  void grid_Loaded(object sender, RoutedEventArgs e)
        {
          
           
        }

        private void ExpandWeiPingHandler(string obj)
        {
            PrismApplication.Current.Dispatcher.InvokeAsync(() =>
            {
                ExpandAllDetails(grid);
            });

        }

        void ExpandAllDetails(GridControl grid)
        {
            for (int i = 0; i < grid.VisibleRowCount; i++)
            {
                int rowHandle = grid.GetRowHandleByVisibleIndex(i);
                grid.ExpandMasterRow(rowHandle);

                var detailGrid = grid.GetDetail(rowHandle) as GridControl;
                if (detailGrid != null)
                {
                    ExpandAllDetails(detailGrid); // 递归展开子级的主从关系
                }
            }
        }



    }
}
